﻿/*-------------------------------------------------------------------------
* 命名空间: SiliconSelect.Models/SlaveState
* 类       名: SlaveState
* 功      能:  从站的状态: 是否连接, 心跳是否正常, 服务器是否开启. 按照它们的这种思路,应该是每个从站都开启了一个Socket
* 时      间:  2023/6/27 17:09:36
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using Newtonsoft.Json.Serialization;
using SiliconSelect.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace SiliconSelect.Models
{
    public class SlaveState : NotifyBase
    {
        /// <summary>
        /// 从站名称,主要用来显示用.
        /// </summary>
        private string? _slaveName;

        public string? SlaveName
        {
            get { return _slaveName; }
            set { SetProperty(ref _slaveName, value); }
        }


        /// <summary>
        /// IP地址
        /// </summary>
        private string? _ip = "192.168.0.1";
        public string? IP
        {
            get { return _ip; }
            set { SetProperty(ref _ip, value); }
        }

        /// <summary>
        /// 通信端口号,因为有五个服务器,所以要为每个服务器都要设置一个端口号.
        /// </summary>
        private int _port = 50001;

        public int Port
        {
            get { return _port; }
            set { SetProperty(ref _port, value); }
        }

        /// <summary>
        /// 是否连接,注意这里用的汉字,主要是和界面进行绑定的.
        /// </summary>
        private string _connectedStatus = "已断开";

        public string ConnectedStatus
        {
            get { return _connectedStatus; }
            set
            {
                if (value == "已断开")
                {
                    ConnectedColor = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    ConnectedColor = new SolidColorBrush(Colors.Green);
                }
                SetProperty(ref _connectedStatus, value);
            }
        }

        /// <summary>
        /// 是否连接对应的状态显示颜色(红色或者是绿色)
        /// </summary>

        private SolidColorBrush? _connectedColor;

        public SolidColorBrush? ConnectedColor
        {
            get { return _connectedColor; }
            set { SetProperty(ref _connectedColor, value); }
        }

        /// <summary>
        /// 心跳状态
        /// </summary>
        private bool _heartStatus = false;

        public bool HeartStatus
        {
            get { return _heartStatus; }
            set
            {
                SetProperty(ref _heartStatus, value);
                if (value)
                {
                    HeartColor = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    HeartColor = new SolidColorBrush(Colors.Red);
                }
            }
        }

        private SolidColorBrush? _heartColor;

        public SolidColorBrush? HeartColor
        {
            get { return _heartColor; }
            set { SetProperty(ref _heartColor, value); }
        }

        /// <summary>
        /// 其对应的服务器是否已经开启.
        /// 准备好了,客户端就可以连接了
        /// </summary>

        private bool _readyStatus = false;

        public bool ReadyStatus
        {
            get { return _readyStatus; }
            set
            {
                SetProperty(ref _readyStatus, value);
                if (value)
                {
                    ReadyColor = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    ReadyColor = new SolidColorBrush(Colors.Red);
                }
            }
        }

        private SolidColorBrush? _readyColor;

        public SolidColorBrush? ReadyColor
        {
            get { return _readyColor; }
            set { SetProperty(ref _readyColor, value); }
        }

        // 端口号修正
        private int _portAdd = 0;

        public int PortAdd
        {
            get { return _portAdd; }
            set { SetProperty(ref _portAdd, value); }
        }

    }
}
